package com.muyu.danmo.controller;


import com.github.pagehelper.PageInfo;
import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.PageUtils;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.danmo.domain.DanmoGalleryWorks;
import com.muyu.danmo.service.IDanmoGalleryWorksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 画廊作品Controller
 *
 * @author yangle
 * @date 2024-10-23
 */
@RestController
@RequestMapping("/galleryWorks")
public class DanmoGalleryWorksController extends BaseController
{
    @Autowired
    private IDanmoGalleryWorksService danmoGalleryWorksService;

    /**
     * 查询画廊作品列表
     */
//    @RequiresPermissions("system:galleryWorks:list")
    @PostMapping("/list")
    public Result<PageInfo<DanmoGalleryWorks>> list(@RequestBody  DanmoGalleryWorks danmoGalleryWorks)
    {
        PageUtils.startPage(danmoGalleryWorks.getPageNum(), danmoGalleryWorks.getPageSize());
        List<DanmoGalleryWorks> list = danmoGalleryWorksService.selectDanmoGalleryWorksList(danmoGalleryWorks);
        PageInfo<DanmoGalleryWorks> danmoGalleryWorksPageInfo = new PageInfo<>(list);
        return Result.success(danmoGalleryWorksPageInfo);
    }

    /**
     * 导出画廊作品列表
     */
//    @RequiresPermissions("system:galleryWorks:export")
    @Log(title = "画廊作品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoGalleryWorks danmoGalleryWorks)
    {
        List<DanmoGalleryWorks> list = danmoGalleryWorksService.selectDanmoGalleryWorksList(danmoGalleryWorks);
        ExcelUtil<DanmoGalleryWorks> util = new ExcelUtil<DanmoGalleryWorks>(DanmoGalleryWorks.class);
        util.exportExcel(response, list, "画廊作品数据");
    }

    /**
     * 获取画廊作品详细信息
     */
//    @RequiresPermissions("system:galleryWorks:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoGalleryWorksService.selectDanmoGalleryWorksById(id));
    }

    /**
     * 新增画廊作品
     */
//    @RequiresPermissions("system:galleryWorks:add")
    @Log(title = "画廊作品", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoGalleryWorks danmoGalleryWorks)
    {
        return Result.success(danmoGalleryWorksService.insertDanmoGalleryWorks(danmoGalleryWorks));
    }

    /**
     * 修改画廊作品
     */
//    @RequiresPermissions("system:galleryWorks:edit")
    @Log(title = "画廊作品", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoGalleryWorks danmoGalleryWorks)
    {
        return Result.success(danmoGalleryWorksService.updateDanmoGalleryWorks(danmoGalleryWorks));
    }

    /**
     * 删除画廊作品
     */
//    @RequiresPermissions("system:galleryWorks:remove")
    @Log(title = "画廊作品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoGalleryWorksService.deleteDanmoGalleryWorksByIds(ids));
    }
}
